import pandas as pd
import json

# 读取 JSON 数据示例
json_data_eg = '''
[
    {
        "_index" : "tob_contract_rent_info_11_v1",
        "_type" : "_doc",
        "_id" : "1250278282963160704",
        "_score" : 1.0,
        "_source" : {
            "contract_no" : "2024071704",
            "database" : "erp_transaction_11",
            "city_code" : 510700,
            "id" : 1250278282963160704,
            "table" : "cont_contract_rent_info"
        }
    }
]
'''

# 读取 JSON 文件
with open('input.json', 'r') as file:
    data = json.load(file)



# 提取 _source 部分的数据，并将 id 转换为字符串
source_data = []
for item in data:
    source_item = item['_source']
    source_item['id'] = str(source_item['id'])
    source_data.append(source_item)

# 将数据转换为 DataFrame
df = pd.DataFrame(source_data)

# 将 DataFrame 保存为 Excel 文件
df.to_excel('output.xlsx', index=False)

print("JSON 数据已成功转换为 Excel 文件：output.xlsx")